<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改报表参数管理')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-param-edit" th:object="${baseReportParam}">
            <input name="idReportParam" th:field="*{idReportParam}" type="hidden">
            <input type="hidden" name="naDateRule" id="naDateRule" th:field="*{naDateRule}">
            <div class="form-group">    
                <label class="col-sm-3 control-label">名称：</label>
                <div class="col-sm-8">
                    <input name="na" th:field="*{na}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">参数：</label>
                <div class="col-sm-8">
                    <textarea name="param" class="form-control" rows="8">[[*{param}]]</textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">日期校验规则：</label>
                <div class="col-sm-8">
                    <select name="sdDateRule" id="sdDateRule" class="form-control m-b" th:with="type=${@baseSd.getItem('report_date_rule')}">
                        <option th:each="item : ${type}" th:text="${item.na}" th:value="${item.cd}" th:selected="*{sdDateRule} eq ${item.cd} "></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">日期类型：</label>
                <div class="col-sm-8">
                    <select name="euDateType" class="form-control">
                        <option value="D" th:selected="*{euDateType=='D'}">天</option>
                        <option value="M" th:selected="*{euDateType=='M'}">月</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">日期分类：</label>
                <div class="col-sm-8">
                    <select name="euDateCls" class="form-control">
                        <option value=0 th:selected="*{euDateCls==0}">单日期</option>
                        <option value=1 th:selected="*{euDateCls==1}">双日期</option>
                        <option value=2 th:selected="*{euDateCls==2}">无</option>
                    </select>
                </div>
            </div>
            <h4 class="form-header h4">过滤字段定义</h4>
            <div class="row">
                <div class="col-sm-12">
                    <button type="button" class="btn btn-white btn-sm" onclick="addRow()"><i class="fa fa-plus"> 增加</i></button>
                    <button type="button" class="btn btn-white btn-sm" onclick="sub.delRow()"><i class="fa fa-minus"> 删除</i></button>
                    <div class="col-sm-12 select-table table-striped">
                        <table id="bootstrap-table"></table>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "base/report/param";
        $("#form-param-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            $("#naDateRule").val($("#sdDateRule").find("option:checked").text());
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-param-edit').serialize());
            }
        }

        $(function() {
            var options = {
                data: [[${baseReportParam.filterList}]],
                pagination: false,
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                sidePagination: "client",
                columns: [{
                    checkbox: true
                },
                    {
                        field: 'index',
                        align: 'center',
                        title: "序号",
                        formatter: function (value, row, index) {
                            var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                            return columnIndex + $.table.serialNumber(index);
                        }
                    },
                    {
                        field: 'cd',
                        align: 'center',
                        title: '编码',
                        formatter: function(value, row, index) {
                            var html = $.common.sprintf("<input class='form-control' type='text' name='filterList[%s].cd' value='%s'>", index, value);
                            return html;
                        }
                    },
                    {
                        field: 'na',
                        align: 'center',
                        title: '名称',
                        formatter: function(value, row, index) {
                            var html = $.common.sprintf("<input class='form-control' type='text' name='filterList[%s].na' value='%s'>", index, value);
                            return html;
                        }
                    },
                    {
                        field: 'sdFilterType',
                        align: 'center',
                        title: '过滤类型',
                        formatter: function(value, row, index) {
                            var html = $.common.sprintf("<input class='form-control' type='text' name='filterList[%s].sdFilterType' value='%s'>", index, value);
                            return html;
                        }
                    },
                    {
                        field: 'naFilterType',
                        align: 'center',
                        title: '过滤类型名称',
                        formatter: function(value, row, index) {
                            var html = $.common.sprintf("<input class='form-control' type='text' name='filterList[%s].naFilterType' value='%s'>", index, value);
                            return html;
                        }
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function(value, row, index) {
                            var value = $.common.isNotEmpty(row.index) ? row.index : $.table.serialNumber(index);
                            return '<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="sub.delRowByIndex(\'' + value + '\')"><i class="fa fa-remove"></i>删除</a>';
                        }
                    }]
            };
            $.table.init(options);
        });

        function addRow() {
            var count = $("#" + table.options.id).bootstrapTable('getData').length;
            var row = {
                index: $.table.serialNumber(count),
                cd: "",
                na: "",
                sdFilterType: "",
                naFilterType: ""
            }
            sub.addRow(row);
        }
    </script>
</body>
</html>